package leetcode.code1734;

import leetcode.IDebug;
import leetcode.helper.H;

public class Solution implements IDebug {

	public int[] decode(int[] encoded) {
		int n = encoded.length;
		int[] ans = new int[n + 1];
		int xor = n + 1;// 1~n + 1的异或和
		int xor2 = 0;// 从第二个数到n + 1的异或和
		for (int i = 1; i <= n; i++) {
			xor ^= i;
			if ((i & 1) == 1 && i < n) {
				xor2 ^= encoded[i];
			}
		}
		ans[0] = xor ^ xor2;// 第一个数
		for (int i = 1; i <= n; i++) {
			ans[i] = ans[i - 1] ^ encoded[i - 1];
		}
		return ans;
	}

	@Override
	public void debug4() {
		H.compare(H.str2array3("[2,4,1,5,3]"), this.decode(H.str2array3("[6,5,4,6]")));

	}

	@Override
	public void debug3() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug2() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug1() {
		// TODO Auto-generated method stub

	}

	public static void main(String[] args) {
		Solution so = new Solution();
		so.debug1();
		so.debug2();
		so.debug3();
		so.debug4();

	}

}
